# -*- coding: utf-8 -*-
# $Id$

# Copyright 2008, 2009 Grigoriy Kuznetsov (gkuznets@yandex.ru)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from PyQt4.QtGui import QTableWidget, QTableWidgetItem
from core.batch import Batch
from gui.colors import *

class OverallTable(QTableWidget):
    """Сводная табличка"""
    def __init__(self, rows, cols, parent=None):
        QTableWidget.__init__(self, rows, cols, parent)
        
    def update(self):
        # Проверяем, что у нас колонок столько же, сколько всего пачек
        if self.rowCount() != len(Batch.all()):
            self.setRowCount(len(Batch.all()))
        # Бежим по клеткам и красим в соотв цвета (-;
        i = 0
        for b in Batch.all():
            self.setRowHeight(i, 10)
            for p in range(6):
                item = QTableWidgetItem()
                item.setBackgroundColor(non_checked_color)
                if p in b.checkedProblems(0):
                    item.setBackgroundColor(checked_once_color)
                if p in b.checkedProblems(1):
                    item.setBackgroundColor(checked_twice_color)
                self.setItem(i, p, item)
            i += 1
                
        QTableWidget.update(self)